package com.dropgame.tools;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.dropgame.main.AssetLoader;

public class MyToastTest {

	private Sprite backGround;
	public Float bScale;
	public ImageButton yesButton;
	public ImageButton noButton;
	private Float xPos = 30.0f;
	private Float yPos = 30.0f;
	private Vector2 center;
	private Sprite yesKeyFrame;
	private Sprite noKeyFrame;
	public Boolean open = false;
	public Boolean close = false;
	
	public MyToastTest(){
		this.backGround = new Sprite();
		this.backGround = AssetLoader.brownToast;
		bScale = 0.00001f;
		center = new Vector2(xPos + backGround.getWidth()/2, yPos + backGround.getHeight()/2);
	}
	
	public MyToastTest(Sprite backGround){
		this.backGround = new Sprite();
		this.backGround = backGround;
		bScale = 0.00001f;
		center = new Vector2(xPos + backGround.getWidth()/2, yPos + backGround.getHeight()/2);

	}
	
	public MyToastTest(ImageButton yesButton, ImageButton noButton, Sprite backGround){
		this.backGround = new Sprite();
		this.backGround = backGround;
		this.yesButton = yesButton;
		this.yesButton.setxPos(60.0f);
		this.yesButton.setyPos(60.0f);
		this.noButton = noButton;
		this.noButton.setxPos(160.0f);
		this.noButton.setyPos(135.0f);
		this.noButton.setAcceptInput(false);
		bScale = 0.00001f;
		center = new Vector2(xPos + backGround.getWidth()/2, yPos + backGround.getHeight()/2);

	}
	
	public void update(float deltaTime, SpriteBatch batcher){
		if(open){
			close = false;
			yesButton.setAcceptInput(true);
			noButton.setAcceptInput(true);
			if(bScale >= 1.0f) bScale = 1.0f;
			else bScale += deltaTime*4;
		}
		
		if(close){
			open = false;
			if(bScale <= 0.0f){ 
				bScale = 0.0f;
				yesButton.setAcceptInput(false);
				noButton.setAcceptInput(false);
				close = false;
				}
			else bScale -= deltaTime*4;
		}
		
		if(open || close){
			this.display(deltaTime, batcher);
		}
	}
	
	public void display(float deltaTime, SpriteBatch batcher){
		backGround.setScale(bScale);
		backGround.draw(batcher);
		yesKeyFrame = yesButton.getKeyFrame(deltaTime);
		noKeyFrame = noButton.getKeyFrame(deltaTime);
		yesKeyFrame.setScale(bScale);
		noKeyFrame.setScale(bScale);
		yesKeyFrame.setPosition(center.x - bScale * 50.0f, center.y - bScale * 50.0f);
		noKeyFrame.setPosition(center.x + bScale * 50.0f, center.y - bScale * 50.0f);
		yesKeyFrame.draw(batcher);
		noKeyFrame.draw(batcher);
		
	}
	
	public Sprite display(float deltaTime){
		if(bScale >= 1.0f) bScale = 1.0f;
		else bScale += deltaTime;
		backGround.setScale(bScale);
		return backGround;
	}
	
	public void openScreen(){
		this.open = true;
		this.close = false;
	}
	
	public void closeScreen(){
		this.close = true;
		this.open = false;
	}
}
